const Sequelize = require('sequelize')
const sequelize = require('../config/index')
const User = require('./user').User
const UserInfo = require('./user').UserInfo

let TaskList = sequelize.define('taskList',{
    id:{
        type:Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        comment:'id',
    },
    headimgurl:{
        type:Sequelize.STRING,
        defaultValue:'',
        comment:'头像',
    },
    name:{
        type:Sequelize.STRING,
        defaultValue:'',
        comment:'任务名称',
    },
    uname:{
        type:Sequelize.STRING,
        defaultValue:'',
        comment:'用户名称',
    },
    cash:{
        type:Sequelize.INTEGER,
        defaultValue:0,
        comment:'支付金额',
    },
    price:{
        type:Sequelize.INTEGER,
        defaultValue:0,
        comment:'任务定价',
    },
    showprice:{
        type:Sequelize.INTEGER,
        defaultValue:0,
        comment:'任务显示价格',
    },
    belong:{
        type:Sequelize.STRING,
        defaultValue:null,
        comment:'任务归属',
    },
    demand:{
        type:Sequelize.STRING,
        defaultValue:'无',
        comment:'任务要求',
    },
    describe:{
        type:Sequelize.STRING,
        defaultValue:'无',
        comment:'任务描述',
    },
    time:{
        type:Sequelize.STRING,
        defaultValue:'无',
        comment:'任务周期',
    },
    status:{
        type:Sequelize.INTEGER,
        defaultValue:0,
        comment:'任务状态 0 1 2 3',
    },
    links1:{
        type:Sequelize.STRING,
        defaultValue:null,
        comment:'参考链接1',
    },
    links2:{
        type:Sequelize.STRING,
        defaultValue:null,
        comment:'参考链接2',
    },
    cut_time:{
        type:Sequelize.STRING,
        defaultValue:null,
        comment:'截止时间',
    },

    img_url1:{
        type:Sequelize.TEXT,
        defaultValue:0,
        comment:'参考图片1',
    },
    img_url2:{
        type:Sequelize.TEXT,
        defaultValue:0,
        comment:'参考图片2',
    },
    img_url3:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'参考图片3',
    },
    address:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'地址',
    },
    sour:{
        type:Sequelize.STRING,
        defaultValue:'个人',
        comment:'任务源 个人或者企业',
    },
    type:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'任务类型',
    },
    isDel:{
        type:Sequelize.STRING,
        defaultValue:0,
        comment:'是否已删除'
    },
},{
    // freezeTabelName 为 true 时不会在库中映射表时增加复数表名
    // 该选项为 true 时，user 在映射时映射成 user，而为 false 时会映射成users
    freezeTableName: true,
})
TaskList.belongsTo(User,{foreignKey: "uid"});
UserInfo.belongsTo(TaskList)
// Skill.belongsToMany(User, {through : 'userSkill'});
//这会创建一个新模型UserProject,其中projectId和userId两个外键。定义through选项后，Sequelize会尝试自动生成名字。
//在本例中，会为User添加方法getUsers,setUsers,addUser,addUsers到Project中。getProjects,setProjects,addProject,addProjects到User中.


let taskList = TaskList.sync();

exports.TaskList = TaskList
